package com.jinhongone.pattern.behavior.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jinho
 * @className SubscribeSubject
 * @description 具体主题角色（被观察者）
 * @date 2025/4/16 15:57
 */
public class SubscribeSubject implements Subject {

    List<Observer> observerList = new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        observerList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        observerList.remove(observer);
    }

    @Override
    public void notify(String msg) {
        //主题变更时，通知观察者们
        for (Observer observer : observerList) {
            observer.update(msg);
        }
    }
}
